﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntitiesLayer.Entities;
using System.Data;
using System.Data.OracleClient;

namespace DataLayer.DAO
{
   public class ReportesDAO
    {
        private Connection.Connection cn;
        private OracleConnection objCn;

        public ReportesDAO()
        { 
            cn = new Connection.Connection();
            objCn = cn.Conecta();
        }

        public List<Reporte> Buscar_Solicitudes_Export(string fecha1, string fecha2)

            {
                List<Reporte> lstObject = new List<Reporte>();

                try
                {
                    OracleCommand cmd = new OracleCommand("Buscar_Solicitudes_Export_01", objCn);
                    objCn.Open();
                    cmd.Connection = objCn;
                    cmd.CommandTimeout = 60;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OracleParameter("RECORDSET", OracleType.Cursor, 100,ParameterDirection.Output,null,DataRowVersion.Current,false,null));
                    cmd.Parameters.Add(new OracleParameter("R_Fecha_Registro1", OracleType.NVarChar, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, fecha1));
                    cmd.Parameters.Add(new OracleParameter("R_Fecha_Registro2", OracleType.NVarChar, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, fecha2));
                    
                    using (IDataReader oRead = cmd.ExecuteReader(CommandBehavior.SingleResult))
                    {
                        if ( oRead != null ){
                            while (oRead.Read())
                            {
                                Reporte oReporte = new Reporte();
                                 
                                if (!oRead.IsDBNull(oRead.GetOrdinal("VREC_COD_REC")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("VREC_COD_REC")).ToString()))
                                    {
                                        oReporte.VREC_COD_REC = oRead.GetString(oRead.GetOrdinal("VREC_COD_REC"));        
                                    }
                                }
                                if (!oRead.IsDBNull(oRead.GetOrdinal("Drec_Fecha_Registro")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetDateTime(oRead.GetOrdinal("Drec_Fecha_Registro")).ToString()))
                                    {
                                        oReporte.Drec_Fecha_Registro = oRead.GetDateTime(oRead.GetOrdinal("Drec_Fecha_Registro"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Reclamante")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Reclamante")).ToString()))
                                    {
                                        oReporte.Reclamante = oRead.GetString(oRead.GetOrdinal("Reclamante"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Paciente")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Paciente")).ToString()))
                                    {
                                        oReporte.Paciente = oRead.GetString(oRead.GetOrdinal("Paciente"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vpac_Telef_Fijo")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vpac_Telef_Fijo")).ToString()))
                                    {
                                        oReporte.Vpac_Telef_Fijo = oRead.GetString(oRead.GetOrdinal("Vpac_Telef_Fijo"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vare_Desc_Area")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vare_Desc_Area")).ToString()))
                                    {
                                        oReporte.Vare_Desc_Area = oRead.GetString(oRead.GetOrdinal("Vare_Desc_Area"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vrec_Ape_Nom_Colab_Inv")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vrec_Ape_Nom_Colab_Inv")).ToString()))
                                    {
                                        oReporte.Vrec_Ape_Nom_Colab_Inv = oRead.GetString(oRead.GetOrdinal("Vrec_Ape_Nom_Colab_Inv"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vpre_Desc_Pre")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vpre_Desc_Pre")).ToString()))
                                    {
                                        oReporte.Vpre_Desc_Pre = oRead.GetString(oRead.GetOrdinal("Vpre_Desc_Pre"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vpac_Desc_Tip_Pac")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vpac_Desc_Tip_Pac")).ToString()))
                                    {
                                        oReporte.Vpac_Desc_Tip_Pac = oRead.GetString(oRead.GetOrdinal("Vpac_Desc_Tip_Pac"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("VSEG_DESC_CIA_SEG")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("VSEG_DESC_CIA_SEG")).ToString()))
                                    {
                                        oReporte.VSEG_DESC_CIA_SEG = oRead.GetString(oRead.GetOrdinal("VSEG_DESC_CIA_SEG"));
                                    }
                                }

                                

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vgen_Desc_Mot_Gen")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vgen_Desc_Mot_Gen")).ToString()))
                                    {
                                        oReporte.Vgen_Desc_Mot_Gen = oRead.GetString(oRead.GetOrdinal("Vgen_Desc_Mot_Gen"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vrec_Desc_Rec")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vrec_Desc_Rec")).ToString()))
                                    {
                                        oReporte.Vrec_Desc_Rec = oRead.GetString(oRead.GetOrdinal("Vrec_Desc_Rec"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vesp_Desc_Mot_Esp")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vesp_Desc_Mot_Esp")).ToString()))
                                    {
                                        oReporte.Vesp_Desc_Mot_Esp = oRead.GetString(oRead.GetOrdinal("Vesp_Desc_Mot_Esp"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vsqr_Desc_Acciones")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vsqr_Desc_Acciones")).ToString()))
                                    {
                                        oReporte.Vsqr_Desc_Acciones = oRead.GetString(oRead.GetOrdinal("Vsqr_Desc_Acciones"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("VQUE_DESC_TIP_QUE")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("VQUE_DESC_TIP_QUE")).ToString()))
                                    {
                                        oReporte.VQUE_DESC_TIP_QUE = oRead.GetString(oRead.GetOrdinal("VQUE_DESC_TIP_QUE"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vest_Nombreestado")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vest_Nombreestado")).ToString()))
                                    {
                                        oReporte.Vest_Nombreestado = oRead.GetString(oRead.GetOrdinal("Vest_Nombreestado"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vsi")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vsi")).ToString()))
                                    {
                                        oReporte.Vsi = oRead.GetString(oRead.GetOrdinal("Vsi"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vno")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vno")).ToString()))
                                    {
                                        oReporte.Vno = oRead.GetString(oRead.GetOrdinal("Vno"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("Vrec_Sustento_Respuesta")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("Vrec_Sustento_Respuesta")).ToString()))
                                    {
                                        oReporte.Vrec_Sustento_Respuesta = oRead.GetString(oRead.GetOrdinal("Vrec_Sustento_Respuesta"));
                                    }
                                }

                                lstObject.Add(oReporte);
                                oReporte = null;
                               }
                        } 
                    }
                                                                               
                }catch (Exception ex){
                    objCn.Dispose();
                }finally{
                    objCn.Close();
                }

                return lstObject;
           
        }


        



    }
}
